home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / ProcDoggie 1.0a6 / UGlobals.inc1.p < prev    next >
Encoding:
Text File  |  1991-02-07  |  10.9 KB  |  371 lines  |  [TEXT/MPS ]

  1. {[j=20/57/1$]}
  2.  
  3. {-------------------------------------------------------------------------------
  4. #
  5. #    Apple Macintosh Developer Technical Support
  6. #
  7. #    Code to implement application utilities
  8. #
  9. #    Program:    ProcDoggie
  10. #    File:        UGlobals.inc1.p - Pascal Implementation
  11. #
  12. #    by:        Forrest Tanaka
  13. #
  14. #    Copyright © 1988-1991 Apple Computer, Inc.
  15. #    All rights reserved.
  16. #
  17. -------------------------------------------------------------------------------}
  18. {[j=20/57/1$] Pasmat Options}
  19. {$R-}
  20.  
  21.  
  22. (*******************************************************************************
  23. * Constants
  24. *******************************************************************************)
  25.  
  26.     CONST
  27.         rOKAlertID       = 6010; {Resource ID of alert with OK button}
  28.         rOKCancelAlertID = 6011; {Resource ID of alert with OK and Cancel buttons}
  29.  
  30.         rIconSuiteID   = 128; {Resource ID of application icon suite}
  31.         rAppNameString = 0;   {Resource ID of application name}
  32.         rAboutAlert    = 258; {Resource ID of About alert}
  33.  
  34.  
  35. (*******************************************************************************
  36. * Variables
  37. *******************************************************************************)
  38.  
  39.     VAR
  40.         gNotification: NMRec; {Notification record}
  41.  
  42.  
  43. {$S Main}
  44. (*******************************************************************************
  45. * Public: DoQuit
  46. *
  47. * The gQuitting global variable is set to TRUE.  This causes the main event loop
  48. * to terminate on the next iteration.
  49. *******************************************************************************)
  50.  
  51.     PROCEDURE DoQuit;
  52.  
  53.     BEGIN
  54.         gQuitting := TRUE
  55.     END;
  56.  
  57.  
  58. {$S Main}
  59. (*******************************************************************************
  60. * Private: NotifyAlert - Present a notification for an alert
  61. *
  62. * This routine is called to present a notification to the user in the form of a
  63. * flashing icon in the application menu whenever an alert from this program is
  64. * displayed.  It’s only necessary to present a notification if this application
  65. * is in the background, so the first check that’s done is to compare our own
  66. * process serial number against the process serial number of the foreground
  67. * process.  If they’re the same, then this application is in the foreground and
  68. * no notification is needed.  If they’re not the same, then the notification is
  69. * presented.
  70. *
  71. * After this application is brought to the front and the alert is dismissed this
  72. * notification is removed by the routine that calls NotifyAlert.
  73. *******************************************************************************)
  74.  
  75.     PROCEDURE NotifyAlert;
  76.  
  77.         VAR
  78.             iconSuite: Handle;      {Handle to the icon suite}
  79.             osEvent:   EventRecord; {OS event for resume}
  80.             error:     OSErr;
  81.  
  82.         PROCEDURE RecoverError (errorCode: OSErr);
  83.  
  84.         BEGIN
  85.             EXIT (NotifyAlert)
  86.         END;
  87.  
  88.     BEGIN
  89.         (* If this application isn’t in front, post a notification *)
  90.         IF NOT gWereInFront THEN
  91.             BEGIN
  92.                 (* Get the small icon for this application *)
  93.                 iconSuite := Get1Resource ('SICN', rIconSuiteID);
  94.                 WITH gNotification DO
  95.                     BEGIN
  96.                         (*WITH*)qType := ORD (nmtype);
  97.                         (*WITH*)nmMark := 1;
  98.                         (*WITH*)nmIcon := iconSuite;
  99.                         (*WITH*)nmSound := Handle(-1);
  100.                         (*WITH*)nmStr := NIL;
  101.                         (*WITH*)nmResp := NIL;
  102.                         (*WITH*)nmRefCon := 0
  103.                     END;
  104.  
  105.                 (* Post the notification *)
  106.                 error := NMINstall (@gNotification);
  107.  
  108.                 (* Wait for a resume event *)
  109.                 WHILE NOT WaitNextEvent (app4Mask, (*<*)osEvent, -1, NIL) DO
  110.                     ;
  111.                 gWereInFront := TRUE;
  112.                 error := NMRemove (@gNotification);
  113.  
  114.                 (* Notification blows away pending update events, so force *)
  115.                 InvalRect (FrontWindow^.portRect);
  116.             END
  117.     END;
  118.  
  119.  
  120. {$S Main}
  121. (*******************************************************************************
  122. * Public: ShowStopAlert
  123. *
  124. * NotifyAlert is called to present a notification to the user in case this
  125. * application is in the background at the time of the alert.  This routine then
  126. * removes the notification after StopAlert is called.
  127. *******************************************************************************)
  128.  
  129.     FUNCTION ShowStopAlert (messageClass: Integer;
  130.                             messageIndex: Integer): Integer;
  131.  
  132.         VAR
  133.             aMessage: Str255; {Contents of message to place in alert}
  134.  
  135.     BEGIN
  136.         (* Put the specified message into the dialog parameter text *)
  137.         GetIndString ((*<*)aMessage, messageClass, messageIndex);
  138.         ParamText (aMessage, '', '', '');
  139.  
  140.         (* Show the stop alert *)
  141.         InitCursor;
  142.         NotifyAlert;
  143.         ShowStopAlert := StopAlert (rOKAlertID, NIL);
  144.     END;
  145.  
  146.  
  147. {$S Main}
  148. (*******************************************************************************
  149. * Public: ShowCautionOKCancelAlert
  150. *
  151. * NotifyAlert is called to present a notification to the user in case this
  152. * application is in the background at the time of the alert.  This routine then
  153. * removes the notification after ShowCautionOKCancelAlert is called.
  154. *******************************************************************************)
  155.  
  156.     FUNCTION ShowCautionOKCancelAlert (messageClass: Integer;
  157.                                        messageIndex: Integer): Integer;
  158.  
  159.         VAR
  160.             aMessage: Str255; {Contents of message to place in alert}
  161.  
  162.     BEGIN
  163.         (* Put the specified message into the dialog parameter text *)
  164.         GetIndString ((*<*)aMessage, messageClass, messageIndex);
  165.         ParamText (aMessage, '', '', '');
  166.  
  167.         (* Show the stop alert *)
  168.         InitCursor;
  169.         NotifyAlert;
  170.         ShowCautionOKCancelAlert := CautionAlert (rOKCancelAlertID, NIL)
  171.     END;
  172.  
  173.  
  174. {$S Main}
  175. (*******************************************************************************
  176. * Public: ShowCautionOKAlert
  177. *
  178. * NotifyAlert is called to present a notification to the user in case this
  179. * application is in the background at the time of the alert.  This routine then
  180. * removes the notification after ShowCautionOKAlert is called.
  181. *******************************************************************************)
  182.  
  183.     FUNCTION ShowCautionOKAlert (messageClass: Integer;
  184.                                  messageIndex: Integer): Integer;
  185.  
  186.         VAR
  187.             aMessage: Str255; {Contents of message to place in alert}
  188.             error:    OSErr;
  189.  
  190.     BEGIN
  191.         (* Put the specified message into the dialog parameter text *)
  192.         GetIndString ((*<*)aMessage, messageClass, messageIndex);
  193.         ParamText (aMessage, '', '', '');
  194.  
  195.         (* Show the stop alert *)
  196.         InitCursor;
  197.         NotifyAlert;
  198.         ShowCautionOKAlert := CautionAlert (rOKAlertID, NIL);
  199.         error := NMRemove (@gNotification)
  200.     END;
  201.  
  202.  
  203. {$S Main}
  204. (*******************************************************************************
  205. * Public: ShowAboutBox
  206. *
  207. * The name and the version number of this application are retrieved from
  208. * resources.  They’re then displayed in the About box using the ParamText
  209. * mechanism.
  210. *******************************************************************************)
  211.  
  212.     PROCEDURE ShowAboutBox;
  213.  
  214.         VAR
  215.             appNameRes: StringHandle; {Handle to name of application}
  216.             curVersion: VersRecHndl;  {Handle to version record of this app}
  217.             appName:    Str255;       {Name of this application}
  218.             verNum:     Str255;       {Long version number of this application}
  219.             itemHit:    Integer;      {Item number of clicked alert item; ignored}
  220.  
  221.     BEGIN
  222.         (* Get the name of this application *)
  223.         appNameRes := GetString (rAppNameString);
  224.         IF appNameRes <> NIL THEN
  225.             appName := appNameRes^^
  226.         ELSE
  227.             appName := '?';
  228.  
  229.         (* Get the version information of this application *)
  230.         curVersion := VersRecHndl (Get1Resource ('vers', 1));
  231.         IF curVersion <> NIL THEN
  232.             (* Get the long version number *)
  233.             verNum := StringPtr(ORD(@curVersion^^.shortVersion) +
  234.                     ORD(curVersion^^.shortVersion[0]) + 1)^
  235.         ELSE
  236.             verNum := '?';
  237.  
  238.         (* Show the About alert *)
  239.         ParamText(appName, verNum, '', '');
  240.         itemHit := Alert (rAboutAlert, NIL);
  241.     END;
  242.  
  243.  
  244. {$S Main}
  245. (*******************************************************************************
  246. * Public: CreateWindow
  247. *
  248. * A WindowRecord is allocated on the heap before GetNewWindow is called.  This
  249. * is done to reduce heap fragmentation.
  250. *******************************************************************************)
  251.  
  252.     FUNCTION CreateWindow (windowTmplID: Integer): WindowPtr;
  253.  
  254.         VAR
  255.             windStore: Ptr;       {Pointer to window record}
  256.             aWindow:   WindowPtr; {Pointer to the new window}
  257.             qdVersion: LongInt;   {Version of QuickDraw on this machine}
  258.             result:    OSErr;
  259.  
  260.         PROCEDURE RecoverError (error: Integer);
  261.  
  262.         BEGIN
  263.             IF aWindow <> NIL THEN
  264.                 CloseWindow (aWindow);
  265.             IF windStore <> NIL THEN
  266.                 DisposPtr (windStore);
  267.             gError := error;
  268.             CreateWindow := NIL;
  269.             EXIT (CreateWindow)
  270.         END;
  271.  
  272.     BEGIN
  273.         windStore := NIL;
  274.         aWindow := NIL;
  275.  
  276.         (* Allocate window record *)
  277.         windStore := NewPtrMargin (SIZEOF (WindowRecord), kAllocApp,
  278.                 NOT kAllocClr);
  279.  
  280.         (* Create the new window *)
  281.         IF windStore = NIL THEN
  282.             RecoverError (memFullErr)
  283.         ELSE
  284.             BEGIN
  285.                 (* Create the new window *)
  286.                 result := Gestalt (gestaltQuickdrawVersion, (*<*)qdVersion);
  287.                 IF qdVersion = gestaltOriginalQD THEN
  288.                     aWindow := GetNewWindow (windowTmplID, windStore, WindowPtr(-1))
  289.                 ELSE
  290.                     aWindow := GetNewCWindow (windowTmplID, windStore,
  291.                              WindowPtr(-1));
  292.                 IF FailLowMemory (0) THEN
  293.                     RecoverError (memFullErr)
  294.                 ELSE IF ResError <> noErr THEN
  295.                     IF ResError = memFullErr THEN
  296.                         RecoverError (memFullErr)
  297.                     ELSE IF (ResError = noErr) | (ResError = resNotFound) THEN
  298.                         RecoverError (resNotFound)
  299.                     ELSE
  300.                         RecoverError (dsSysErr);
  301.  
  302.                 SetPort (aWindow);
  303.                 SetWRefCon (aWindow, 0)
  304.             END;
  305.         CreateWindow := aWindow
  306.     END;
  307.  
  308.  
  309. {$S Main}
  310. (*******************************************************************************
  311. * Public: CreateDialog
  312. *
  313. * A DialogRecord is allocated on the heap before GetNewWindow is called.  This
  314. * is done to reduce heap fragmentation.
  315. *******************************************************************************)
  316.  
  317.     FUNCTION CreateDialog (dialogTmplID: Integer): DialogPtr;
  318.  
  319.         VAR
  320.             dlogStore: Ptr;       {Pointer to dialog record}
  321.             aDialog:   DialogPtr; {Pointer to the new dialog window}
  322.             qdVersion: LongInt;   {Version of QuickDraw on this machine}
  323.             result:    OSErr;
  324.  
  325.         PROCEDURE RecoverError (error: Integer);
  326.  
  327.         BEGIN
  328.             IF aDialog <> NIL THEN
  329.                 CloseWindow (aDialog);
  330.             IF dlogStore <> NIL THEN
  331.                 DisposPtr (dlogStore);
  332.             gError := error;
  333.             CreateDialog := NIL;
  334.             EXIT (CreateDialog)
  335.         END;
  336.  
  337.     BEGIN
  338.         dlogStore := NIL;
  339.         aDialog := NIL;
  340.  
  341.         (* Allocate window record *)
  342.         dlogStore := NewPtrMargin (SizeOf (DialogRecord), kAllocApp,
  343.                 NOT kAllocClr);
  344.  
  345.         (* Create the new window *)
  346.         IF dlogStore = NIL THEN
  347.             RecoverError (memFullErr)
  348.         ELSE
  349.             BEGIN
  350.                 result := Gestalt (gestaltQuickdrawVersion, (*<*)qdVersion);
  351.                 IF qdVersion = gestaltOriginalQD THEN
  352.                     aDialog := GetNewWindow (dialogTmplID, dlogStore, WindowPtr(-1))
  353.                 ELSE
  354.                     aDialog := GetNewCWindow (dialogTmplID, dlogStore,
  355.                             WindowPtr(-1));
  356.                 IF FailLowMemory (0) THEN
  357.                     RecoverError (memFullErr)
  358.                 ELSE IF ResError <> noErr THEN
  359.                     IF ResError = memFullErr THEN
  360.                         RecoverError (memFullErr)
  361.                     ELSE IF (ResError = noErr) | (ResError = resNotFound) THEN
  362.                         RecoverError (resNotFound)
  363.                     ELSE
  364.                         RecoverError (dsSysErr);
  365.  
  366.                 SetPort (aDialog);
  367.                 SetWRefCon (aDialog, 0)
  368.             END;
  369.         CreateDialog := aDialog
  370.     END;
  371.